package org.geek.seckill.enums;

/**
 * 使用枚举表示常量数据字段
 * @author simple
 */
public enum SeckillStateEnums {
    /**
     * 秒杀成功
     */
    SUCCESS(1, "Seckill success!"),
    /**
     * 秒杀结束
     */
    END(0, "Seckill ended!"),
    /**
     * 重复秒杀
     */
    REPEAT_KILL(-1, "Seckill repeated!"),
    /**
     * 系统异常
     */
    INNER_ERROR(-2, "System error!"),
    /**
     * 数据篡改
     */
    DATA_REWRITE(-3, "Data tampered!");

    private int state;

    private String stateInfo;

    SeckillStateEnums(int state, String stateInfo) {
        this.state = state;
        this.stateInfo = stateInfo;
    }

    public static SeckillStateEnums stateOf(int index) {
        for (SeckillStateEnums state : values()) {
            if (state.getState() == index) {
                return state;
            }
        }
        return null;
    }

    public int getState() {
        return state;
    }

    public String getStateInfo() {
        return stateInfo;
    }
}
